home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 2841 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.9 KB

  1. Path: news.ios.com!usenet
  2. From: vlad@gramercy.ios.com (Vlastimil Adamovsky)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Smart Pointer Implementation & question
  5. Date: Sat, 20 Jan 1996 00:46:26 GMT
  6. Organization: Internet Online Services
  7. Message-ID: <4dpdqe$1oc@news.ios.com>
  8. References: <4dfe36$d99@grid.direct.ca> <749@beech.ukc.ac.uk> <DLDw3H.7L1@research.att.com>
  9. NNTP-Posting-Host: ppp-41.ts-7.hck.idt.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. bs@research.att.com (Bjarne Stroustrup <9758-26353> 0112760) wrote:
  13.  
  14.  
  15. >Article 125614 of comp.lang.c++:
  16.  
  17. >From: R.E.Jones@ukc.ac.uk (rej) writes
  18.  
  19. > > In article <4dfe36$d99@grid.direct.ca>, Ken Clark <ken@direct.ca> wrote:
  20. > > >Hi.  I have implemented a reference counting smart pointer class.  It works 
  21. > > >well, except that I can't get a basic behavior of normal pointers:
  22. > > >automatic casting of subclass pointers.
  23. > > 
  24. > > This is a well-known problem with smart pointers.
  25. > > 
  26. > > A good survey of the extent of the problem and possible solutions can be
  27. > > found in
  28. > > 
  29. > > @inproceedings{edel92b,
  30. > > author = "Daniel R. Edelson",
  31. > > title = "Smart Pointers: They're Smart, But They're Not Pointers",
  32. > > booktitle = "USENIX C++ Conference",
  33. > > year = 1992
  34. > > }
  35.  
  36. >However, things have progressed since that paper was written.
  37.  
  38. >The problem is discussed in sec15.9.1 of D&E. You need member templates.
  39. >Here is the key example:
  40.  
  41. >template<class T> class Ptr { // pointer to T
  42. >    T* p;
  43. >public:       
  44. >    Ptr(T*);
  45. >    template<class T2> operator Ptr<T2> () {
  46. >        return Ptr<T2>(p); // works iff p can be
  47. >                           // converted to a T2*
  48. >    }
  49. >    // ...
  50. >};
  51.  
  52. >That way, a Ptr<D> will convert to a Ptr<B> iff a D* converts to B*.
  53.  
  54. >    - Bjarne
  55.  
  56. Which compiler does support the member templates?
  57.  
  58.  
  59. *******************************************
  60. *    Vlastimil Adamovsky                  *
  61. *  Smalltalk and C++ development          *
  62. *******************************************
  63.  
  64.